"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.沙皇Handler = void 0;
const Config_1 = require("../../Config");
const Big_1 = require("../Big");
const Point_1 = require("../Point");
const Utils_1 = __importDefault(require("../Utils"));
class 沙皇Handler {
    constructor(gameMgr, handlerMgr) {
        this.gameMgr = gameMgr;
        this.handlerMgr = handlerMgr;
    }
    gc() {
        this.gameMgr = null;
        this.handlerMgr = null;
    }
    move(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_BIG_MOVE);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        let big_end = endPoint.big;
        if (big_end != null) {
            big_end.deleteState(Big_1.BigState.HIDE);
            big_start.die(player, endPoint.id);
            return;
        }
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("big_move", { "start": data.start, "end": data.end }));
    }
    /** 大子攻击 */
    attack(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_BIG_ATTACK);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        let small = endPoint.small;
        let big_end = endPoint.big;
        if (endPoint.terrain == Point_1.Terrain.JING) {
            //水晶被攻击
            this.gameMgr.gameOver(player);
        }
        else if (small != null) {
            //小子被攻击
            small.die(player);
        }
        else if (big_end != null) {
            //大子被攻击
            if (big_end.attacked(player)) {
                //打过了
            }
            else {
                //攻击没打过，自己死亡
                big_start.die(player, endPoint.id);
                return;
            }
        }
        //没有大子，就是移动
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("big_move", { "start": data.start, "end": data.end }));
    }
}
exports.沙皇Handler = 沙皇Handler;
